package com.example.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.example.common.HttpStatusConstants;
import com.example.common.R;
import com.example.model.req.AddOrderReq;
import com.example.service.AppointmentService;

@ResponseBody
@RestController
@RequestMapping("/appointment")
public class AppointmentController {

    @Autowired
    private AppointmentService appointmentService;
    @Autowired
    private HttpServletRequest request;

    @PostMapping("/addAppointment")
    public R<String> addAppointment(@RequestBody AddOrderReq addOrderReq) {
        return appointmentService.addAppointment(addOrderReq, request);
    }

    // 退款申请
    @PostMapping("/reback/{appointmentId}")
    public R<String> appointmentReback(@PathVariable("appointmentId") Integer appointmentId) {
        if (appointmentId == null) {
            return R.error(HttpStatusConstants.SERVICE_UNAVAILABLE, "");
        }
        return appointmentService.appointmentReback(appointmentId, request);
    }

    // 结束订单
    @PostMapping("/complete")
    public R<String> completeAppointment(@RequestParam("appointmentId") Integer appointmentId) {
        if (appointmentId == null) {
            return R.error(HttpStatusConstants.SERVICE_UNAVAILABLE, "");
        }
        return appointmentService.completeAppointment(appointmentId);
    }

    @PostMapping("/employee/progressAppointment")
    public R<String>  progressAppointment(@RequestParam("appointmentId") Integer appointmentId){
        if (appointmentId == null) {
            return R.error(HttpStatusConstants.SERVICE_UNAVAILABLE, "");
        }
        return appointmentService.progressAppointment(appointmentId);
    }
}
